{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Screen Routines\n", "\n", "Subroutines to make an 78 x 25 character screen.\n", "\n", "* R7 is return value\n", "* R6 is top of stack\n", "* Subroutine (callee) handles saving/loading of return values and registers\n" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Assembled! Use %dis or %dump to examine.\n" ] } ], "source": [ ".ORIG x4000\n", " ;; ------------------------------------------------\n", " ;; Graphics Routines\n", " ;; 78 x 25 (25th for special status)\n", " ;; ------------------------------------------------\n", " ;; SETUP \n", " ;; RESERVED: R6 for stack\n", " ;; R7 for RET value\n", " ;; ------------------------------------------------\n", " LEA R6, STACK ;; R6 is Top of STACK\n", " ;; ------------------------------------------------\n", " LEA R0, START ;; GOTO START\n", " JMP R0 ;; Keep STACK close to reference\n", "STACK: .BLKW #100 ;; adjust size for your use\n", "START: JSR DRAWSCREEN ;; start of actual program\n", " HALT\n", " ;; ------------------------------------------------\n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; Start of Subroutinues:\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; DRAWSCREEN - draw a 80 x 25 screen\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "DRAWSCREEN: STR R7, R6, #0 ;; Save R7 to Stack\n", " ADD R6, R6, #1 ;; Increment Stack\n", " ;;JSR SAVE_REGS\n", " ;;; ---\n", " LD R1, OUTPUT1 ;; read OUTPUTS\n", " LD R2, OUTPUT2 ;; read OUTPUTC\n", " STR R1, R2, #0 ;; save R1 to R2\n", " JSR BORDER ;; draw top border\n", " AND R2, R2, #0 ;; row count is in R2\n", "ROW: JSR SCREENROW\n", " ADD R2, R2, #+1\n", " LD R3, NEGTWENTYFIVE ;; -25\n", " ADD R3, R2, R3\n", " BRn ROW\n", " JSR BORDER\n", " AND R0, R0, #0 ;; terminating \\0\n", " JSR OUTPUT\n", " LD R0, OUTPUT1 ;; read OUTPUTS\n", " ;;PUTS\n", " ;;; ---\n", " ;;JSR RESTORE_REGS\n", " ADD R6, R6, #-1 ;; Decrement Stack\n", " LDR R7, R6, #0 ;; Load Stack into R7\n", " RET \n", "OUTPUT1: .FILL OUTPUTS ;; store OUTPUTS close\n", "OUTPUT2: .FILL OUTPUTC ;; store OUTPUTC close\n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; SCREENROW - draws memory row part of screen\n", ";; - assumes R2 has row count (25, 0)\n", ";; - uses R0\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "SCREENROW: STR R7, R6, #0 ;; Save R7 to Stack\n", " ADD R6, R6, #1 ;; Increment Stack\n", " ;; stuff here\n", " LD R0, BAR\n", " JSR OUTPUT\n", " ;; screen row memory is in R2 (initially zero)\n", " ;; multiply row x 78 to get next\n", " LD R3, SWIDTH\n", " JSR MULTIPLY ;; R2 x R3 -> R4\n", " ;; R4 is now where to start in SCREEN\n", " ;; start in SCREEN + R4\n", " ;; show each word, for SWIDTH times\n", " ADD R5, R3, #0 ;; copy for countdown\n", " LEA R3, SCREEN ;; start of memory\n", " ADD R3, R3, R4 ;; R3 (screen) + R4 (mult)\n", " LD R1, THIRTYTWO ;; ASCII space; maps 0 to ...\n", "SRAGAIN: LDR R0, R3, #0\n", " ADD R0, R0, R1 \n", " JSR OUTPUT\n", " ADD R3, R3, #1\n", " ADD R5, R5, #-1\n", " BRp SRAGAIN\n", " LD R0, BAR\n", " JSR OUTPUT\n", " LD R0, NEWLINE\n", " JSR OUTPUT\n", " ;; end here\n", " ADD R6, R6, #-1 ;; Decrement Stack\n", " LDR R7, R6, #0 ;; Load Stack into R7\n", " RET \n", "THIRTYTWO: .FILL #32\n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; BORDER - draw top/bottom border\n", ";; - uses R0, R1\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "BORDER: STR R7, R6, #0 ;; Save R7 to Stack\n", " ADD R6, R6, #1 ;; Increment Stack\n", " LD R0, PLUS\n", " JSR OUTPUT\n", " AND R1, R1, #0 ;; counter\n", " LD R1, SWIDTH\n", " LD R0, DASH\n", "SAGAIN: JSR OUTPUT\n", " ADD R1, R1, #-1\n", " BRp SAGAIN\n", " LD R0, PLUS\n", " JSR OUTPUT\n", " LD R0, NEWLINE\n", " JSR OUTPUT\n", " ADD R6, R6, #-1 ;; Decrement Stack\n", " LDR R7, R6, #0 ;; Load Stack into R7\n", " RET\n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; MULTIPLY - multiplies R2 x R3 -> R4\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "MULTIPLY: STR R7, R6, #0 ;; Save R7 to Stack\n", " ADD R6, R6, #1 ;; Increment Stack \n", " ;; ---\n", " AND R4, R4, #0 ;; total\n", " AND R5, R5, #0 ;; counter\n", " ADD R5, R5, R2 ;; set condition codes; R5 is copy of R2\n", "MAGAIN: BRz DONE ;; if R5 == 0, done\n", " ADD R4, R4, R3 ;; \n", " ADD R5, R5, #-1 ;; set condition codes\n", " BR MAGAIN\n", " ;; --- result is in R4\n", "DONE: ADD R6, R6, #-1 ;; Decrement Stack\n", " LDR R7, R6, #0 ;; Load Stack into R7\n", " RET \n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; OUTPUT - copy R0 to OUTPUTC (current output)\n", ";; - assumes char in R0\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "OUTPUT: STR R7, R6, #0 ;; Save R7 to Stack\n", " ADD R6, R6, #1 ;; Increment Stack \n", " ;;JSR SAVE_REGS\n", " ;; ---\n", " ;;LDI R4, OUTPUT3 ;; Load OUTPUTC (next char pos)\n", " ;;STR R0, R4, #0 ;; save R0 char to R1 address\n", " ;;ADD R4, R4, #1 ;; increment R1\n", " ;;STI R4, OUTPUT3 ;; Save OUTPUTC\n", " OUT\n", " ;; --- \n", " ;;JSR RESTORE_REGS\n", " ADD R6, R6, #-1 ;; Decrement Stack\n", " LDR R7, R6, #0 ;; Load Stack into R7\n", " RET \n", "OUTPUT3: .FILL OUTPUTC\n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; DATA:\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "SWIDTH .FILL #78 ;; width of screen\n", "PLUS: .FILL #43 ;; + in ASCII\n", "DASH: .FILL #45 ;; - in ASCII\n", "BAR: .FILL #124 ;; | in ASCII\n", "NEWLINE: .FILL #10 ;; NEWLINE in ASCII\n", "NEGTWENTYFIVE: .FILL #-25\n", "SCREEN: .BLKW #1950 ;; 78 x 25\n", "OUTPUTC: .FILL #0\n", "OUTPUTS: .BLKW #1975 ;; 79 x 25\n", ".END" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Screen Display\n", "\n", "This uses a zero-based display screen where 0 is interpreted to be 0 + 32 = x20 (space in ASCII). See ASCII chart for more characters (0 through 94 are mapped to ASCII 32 through 126). Why? Because no need to attempt to display ASCII 0 through 31, which are control codes)." ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Memory disassembled:\n", "============================================================\n", " x40EA: x0011 - 17 (or 17)\n" ] } ], "source": [ "%mem x40EA x11" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Memory disassembled:\n", "============================================================\n", " x40EB: x0012 - 18 (or 18)\n" ] } ], "source": [ "%mem x40EB x12" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Memory disassembled:\n", "============================================================\n", " x4138: x0013 - 19 (or 19)\n" ] } ], "source": [ "%mem x4138 x13" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "+------------------------------------------------------------------------------+\n", "| 12 |\n", "| 3 |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "+------------------------------------------------------------------------------+\n", "\u0000============================================================\n", "Computation completed\n", "============================================================\n", "Instructions: 40446\n", "Cycles: 315249 (0.157625 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x048E\n", "N: 0 Z: 0 P: 1 \n", "R0: x485F R1: x0000 R2: x0019 R3: x0000 \n", "R4: x0750 R5: x0000 R6: x4003 R7: x4069 \n", "Time: 1.9066553115844727 seconds.\n", "\n" ] } ], "source": [ "%%time\n", "%exe" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Welcome to the LC-3 simulator.\n", "\n", "The contents of the LC-3 tools distribution, including sources, management\n", "tools, and data, are Copyright (c) 2003 Steven S. Lumetta.\n", "\n", "The LC-3 tools distribution is free software covered by the GNU General\n", "Public License, and you are welcome to modify it and/or distribute copies\n", "of it under certain conditions. The file COPYING (distributed with the\n", "tools) specifies those conditions. There is absolutely no warranty for\n", "the LC-3 tools distribution, as described in the file NO_WARRANTY (also\n", "distributed with the tools).\n", "\n", "Have fun.\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x3000\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ "%reset" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Assembled! Use %dis or %dump to examine.\n" ] } ], "source": [ ".ORIG x4000\n", ".SET MODE TERMINAL\n", " ;; ------------------------------------------------\n", " ;; Graphics Routines\n", " ;; 78 x 25 (25th for special status)\n", " ;; ------------------------------------------------\n", " ;; SETUP \n", " ;; RESERVED: R6 for stack\n", " ;; R7 for RET value\n", " ;; ------------------------------------------------\n", " LEA R6, STACK ;; R6 is Top of STACK\n", " ;; ------------------------------------------------\n", " LEA R0, START ;; GOTO START\n", " JMP R0 ;; Keep STACK close to reference\n", "STACK: .BLKW #100 ;; adjust size for your use\n", "START: JSR DRAWSCREEN ;; start of actual program\n", " HALT\n", " ;; ------------------------------------------------\n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; Start of Subroutinues:\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; DRAWSCREEN - draw a 80 x 25 screen\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "DRAWSCREEN: STR R7, R6, #0 ;; Save R7 to Stack\n", " ADD R6, R6, #1 ;; Increment Stack\n", " ;;JSR SAVE_REGS\n", " ;;; ---\n", " LD R1, OUTPUT1 ;; read OUTPUTS\n", " LD R2, OUTPUT2 ;; read OUTPUTC\n", " STR R1, R2, #0 ;; save R1 to R2\n", " JSR BORDER ;; draw top border\n", " AND R2, R2, #0 ;; row count is in R2\n", "ROW: JSR SCREENROW\n", " ADD R2, R2, #+1\n", " LD R3, NEGTWENTYFIVE ;; -25\n", " ADD R3, R2, R3\n", " BRn ROW\n", " JSR BORDER\n", " AND R0, R0, #0 ;; terminating \\0\n", " JSR OUTPUT\n", " LD R0, OUTPUT1 ;; read OUTPUTS\n", " ;;PUTS\n", " TERMINAL R0, 0\n", " TERMINAL R0, 1\n", " ;;; ---\n", " ;;JSR RESTORE_REGS\n", " ADD R6, R6, #-1 ;; Decrement Stack\n", " LDR R7, R6, #0 ;; Load Stack into R7\n", " RET \n", "OUTPUT1: .FILL OUTPUTS ;; store OUTPUTS close\n", "OUTPUT2: .FILL OUTPUTC ;; store OUTPUTC close\n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; SCREENROW - draws memory row part of screen\n", ";; - assumes R2 has row count (25, 0)\n", ";; - uses R0\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "SCREENROW: STR R7, R6, #0 ;; Save R7 to Stack\n", " ADD R6, R6, #1 ;; Increment Stack\n", " ;; stuff here\n", " LD R0, BAR\n", " JSR OUTPUT\n", " ;; screen row memory is in R2 (initially zero)\n", " ;; multiply row x 78 to get next\n", " LD R3, SWIDTH\n", " JSR MULTIPLY ;; R2 x R3 -> R4\n", " ;; R4 is now where to start in SCREEN\n", " ;; start in SCREEN + R4\n", " ;; show each word, for SWIDTH times\n", " ADD R5, R3, #0 ;; copy for countdown\n", " LEA R3, SCREEN ;; start of memory\n", " ADD R3, R3, R4 ;; R3 (screen) + R4 (mult)\n", " LD R1, THIRTYTWO ;; ASCII space; maps 0 to ...\n", "SRAGAIN: LDR R0, R3, #0\n", " ADD R0, R0, R1 \n", " JSR OUTPUT\n", " ADD R3, R3, #1\n", " ADD R5, R5, #-1\n", " BRp SRAGAIN\n", " LD R0, BAR\n", " JSR OUTPUT\n", " LD R0, NEWLINE\n", " JSR OUTPUT\n", " ;; end here\n", " ADD R6, R6, #-1 ;; Decrement Stack\n", " LDR R7, R6, #0 ;; Load Stack into R7\n", " RET \n", "THIRTYTWO: .FILL #32\n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; BORDER - draw top/bottom border\n", ";; - uses R0, R1\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "BORDER: STR R7, R6, #0 ;; Save R7 to Stack\n", " ADD R6, R6, #1 ;; Increment Stack\n", " LD R0, PLUS\n", " JSR OUTPUT\n", " AND R1, R1, #0 ;; counter\n", " LD R1, SWIDTH\n", " LD R0, DASH\n", "SAGAIN: JSR OUTPUT\n", " ADD R1, R1, #-1\n", " BRp SAGAIN\n", " LD R0, PLUS\n", " JSR OUTPUT\n", " LD R0, NEWLINE\n", " JSR OUTPUT\n", " ADD R6, R6, #-1 ;; Decrement Stack\n", " LDR R7, R6, #0 ;; Load Stack into R7\n", " RET\n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; MULTIPLY - multiplies R2 x R3 -> R4\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "MULTIPLY: STR R7, R6, #0 ;; Save R7 to Stack\n", " ADD R6, R6, #1 ;; Increment Stack \n", " ;; ---\n", " AND R4, R4, #0 ;; total\n", " AND R5, R5, #0 ;; counter\n", " ADD R5, R5, R2 ;; set condition codes; R5 is copy of R2\n", "MAGAIN: BRz DONE ;; if R5 == 0, done\n", " ADD R4, R4, R3 ;; \n", " ADD R5, R5, #-1 ;; set condition codes\n", " BR MAGAIN\n", " ;; --- result is in R4\n", "DONE: ADD R6, R6, #-1 ;; Decrement Stack\n", " LDR R7, R6, #0 ;; Load Stack into R7\n", " RET \n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; OUTPUT - copy R0 to OUTPUTC (current output)\n", ";; - assumes char in R0\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "OUTPUT: STR R7, R6, #0 ;; Save R7 to Stack\n", " ADD R6, R6, #1 ;; Increment Stack \n", " ;; ---\n", " LDI R4, OUTPUT3 ;; Load OUTPUTC (next char pos)\n", " STR R0, R4, #0 ;; save R0 char to R1 address\n", " ADD R4, R4, #1 ;; increment R1\n", " STI R4, OUTPUT3 ;; Save OUTPUTC\n", " ;;OUT\n", " ;; --- \n", " ADD R6, R6, #-1 ;; Decrement Stack\n", " LDR R7, R6, #0 ;; Load Stack into R7\n", " RET \n", "OUTPUT3: .FILL OUTPUTC\n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; DATA:\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "SWIDTH .FILL #78 ;; width of screen\n", "PLUS: .FILL #43 ;; + in ASCII\n", "DASH: .FILL #45 ;; - in ASCII\n", "BAR: .FILL #124 ;; | in ASCII\n", "NEWLINE: .FILL #10 ;; NEWLINE in ASCII\n", "NEGTWENTYFIVE: .FILL #-25\n", "SCREEN: .BLKW #1950 ;; 78 x 25\n", "OUTPUTC: .FILL #0\n", "OUTPUTS: .BLKW #1975 ;; 79 x 25\n", ".END" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
+------------------------------------------------------------------------------+\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "+------------------------------------------------------------------------------+\n",
       "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Computation completed\n", "============================================================\n", "Instructions: 33884\n", "Cycles: 262759 (0.131380 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x048E\n", "N: 0 Z: 0 P: 1 \n", "R0: x4864 R1: x0000 R2: x0019 R3: x0000 \n", "R4: x50F0 R5: x0000 R6: x4003 R7: x4069 \n", "Time: 0.4796028137207031 seconds.\n", "\n" ] } ], "source": [ "%%time\n", "%exe" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
+------------------------------------------------------------------------------+\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "|                                                                              |\n",
       "+------------------------------------------------------------------------------+\n",
       "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Computation completed\n", "============================================================\n", "Instructions: 33884\n", "Cycles: 262759 (0.131380 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x048E\n", "N: 0 Z: 0 P: 1 \n", "R0: x4864 R1: x0000 R2: x0019 R3: x0000 \n", "R4: x50F0 R5: x0000 R6: x4003 R7: x4069 \n", "Time: 0.4615483283996582 seconds.\n", "\n" ] } ], "source": [ "%%time\n", "%exe" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Assembled! Use %dis or %dump to examine.\n" ] } ], "source": [ ".ORIG x5000\n", " ;; ------------------------------------------------\n", " LEA R6, STACK ;; R6 is Top of STACK\n", " ;; ------------------------------------------------\n", " LEA R0, START ;; GOTO START\n", " JMP R0 ;; Keep STACK close to reference\n", "STACK: .BLKW #100 ;; adjust size for your use\n", "START: LD R2, FIVE\n", " LD R3, SIX\n", " JSR MULTIPLY\n", " HALT\n", "FIVE: .FILL #5\n", "SIX: .FILL #6\n", "\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", ";; MULTIPLY - multiplies R2 x R3 -> R4\n", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n", "MULTIPLY: STR R7, R6, #0 ;; Save R7 to Stack\n", " ADD R6, R6, #1 ;; Increment Stack \n", " ;;JSR SAVE_REGS\n", " ;; ---\n", " AND R4, R4, #0 ;; total\n", " AND R5, R5, #0 ;; counter\n", " ADD R5, R5, R2 ;; set condition codes; R5 is copy of R2\n", "MAGAIN: BRz DONE ;; if R5 == 0, done\n", " ADD R4, R4, R3 ;; \n", " ADD R5, R5, #-1 ;; set condition codes\n", " BR MAGAIN\n", " ;; --- result is in R4\n", " ;;JSR RESTORE_REGS\n", "DONE: ADD R6, R6, #-1 ;; Decrement Stack\n", " LDR R7, R6, #0 ;; Load Stack into R7\n", " RET \n", "\n", ".END" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Computation completed\n", "============================================================\n", "Instructions: 36\n", "Cycles: 235 (0.000117 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x048E\n", "N: 0 Z: 0 P: 1 \n", "R0: x5067 R1: x0000 R2: x0005 R3: x0006 \n", "R4: x001E R5: x0000 R6: x5003 R7: x506B \n" ] } ], "source": [ "%exe" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Welcome to the LC-3 simulator.\n", "\n", "The contents of the LC-3 tools distribution, including sources, management\n", "tools, and data, are Copyright (c) 2003 Steven S. Lumetta.\n", "\n", "The LC-3 tools distribution is free software covered by the GNU General\n", "Public License, and you are welcome to modify it and/or distribute copies\n", "of it under certain conditions. The file COPYING (distributed with the\n", "tools) specifies those conditions. There is absolutely no warranty for\n", "the LC-3 tools distribution, as described in the file NO_WARRANTY (also\n", "distributed with the tools).\n", "\n", "Have fun.\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x3000\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ "%reset" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Calysto LC3", "language": "gas", "name": "calysto_lc3" }, "language_info": { "codemirror_mode": { "name": "gas", "version": 3 }, "file_extension": ".asm", "mimetype": "text/x-gas", "name": "gas" } }, "nbformat": 4, "nbformat_minor": 0 }